package com.cute.leetcode.editor.cn;

import java.util.*;

public class HJ41ChengFaMa {
    /**
     * n砝码种类数
     * weights为砝码质量
     * nums为每种砝码有多少个
     * 求最后可以称重的总种类数，包括0
     * 使用dfs会超时，用三重遍历：遍历重量，遍历数量，遍历结果
     */
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()){
            int n = sc.nextInt();
            int[] weights = new int[n];
            int[] nums = new int[n];
            Set<Integer> set = new HashSet<>();
            set.add(0);// 添加重量0
            for (int i = 0; i < n; i++) weights[i] = sc.nextInt();
            for (int i = 0; i < n; i++) nums[i] = sc.nextInt();
            for (int j = 0; j < n; j++){// 遍历重量
                ArrayList<Integer> temp = new ArrayList<>(set);// 取得之前砝码能到的重量
                for (int i = 1; i <= nums[j]; i++){// 遍历数量
                    for (int sum : temp) {// 遍历之前的结果
                        set.add(sum + i * weights[j]);
                    }
                }
            }
            System.out.println(set.size());
        }
    }
}
